#include "CornerLampView.h"
#include "F3LampInterfaces.h"

static void CL_CanSignalFeedback(CornerLampView* this_)
{
    Set_CANSIG_LCU_FL_FLCornerLampOnSt(this_->lastModel_.onOffStatus_);
}

float calculateClDerateCoefficient()
{
    float coefficient = 100.0f;

    do
    {
        if(IsLoBeamNTCOpenCircuit())
        {
            //Ignore
            break;
        }

        if(IsCornerLampNTCShortCircuit() || IsCornerLampNTCOpenCircuit())
        {
            coefficient = LocalQuery_CornerLampBrightness_Temperature();
        }

    } while (false);
    

    float coefficient_v = LocalQuery_CornerLampBrightness_Voltage();
    coefficient = coefficient < coefficient_v ? coefficient : coefficient_v;

    return coefficient;
}

void execute_CornerView(CornerLampView* this_)
{
    CL_CanSignalFeedback(this_);
    Set_Corner_OnOffState(IsLampTurnOn(this_->model_->onOffStatus_));
	Set_CL_SW(IsLampTurnOn(this_->model_->onOffStatus_));
    Set_Corner_brightness(100.0f * calculateClDerateCoefficient() / 100.0f);
}
